// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import UIKit

public struct ToolbarElement: Equatable {
    /// Icon name of the toolbar element
    let iconName: String

    /// Badge name of the toolbar element
    let badgeImageName: String?

    /// Number of open tabs
    let numberOfTabs: Int?

    /// Whether the toolbar element can be interacted with
    let isEnabled: Bool

    /// Indicates if the element should be displayed as highlighted
    let shouldDisplayAsHighlighted: Bool

    /// Accessibility label of the toolbar element
    let a11yLabel: String

    /// Accessibility hint of the toolbar element
    let a11yHint: String?

    /// Accessibility identifier of the toolbar element
    let a11yId: String

    /// Closure that is executed when the toolbar element is tapped
    let onSelected: ((UIButton) -> Void)?

    /// Closure that is executed when the toolbar element is long pressed
    let onLongPress: (() -> Void)?

    // We need this init as by default the init generated by the compiler for the struct will be internal and
    // can therefor not be used outside of the ToolbarKit
    public init(iconName: String,
                badgeImageName: String? = nil,
                numberOfTabs: Int? = nil,
                isEnabled: Bool,
                shouldDisplayAsHighlighted: Bool = false,
                a11yLabel: String,
                a11yHint: String?,
                a11yId: String,
                onSelected: ((UIButton) -> Void)?,
                onLongPress: (() -> Void)? = nil) {
        self.iconName = iconName
        self.badgeImageName = badgeImageName
        self.numberOfTabs = numberOfTabs
        self.isEnabled = isEnabled
        self.shouldDisplayAsHighlighted = shouldDisplayAsHighlighted
        self.onSelected = onSelected
        self.onLongPress = onLongPress
        self.a11yLabel = a11yLabel
        self.a11yHint = a11yHint
        self.a11yId = a11yId
    }

    public static func == (lhs: ToolbarElement, rhs: ToolbarElement) -> Bool {
        lhs.iconName == rhs.iconName &&
        lhs.badgeImageName == rhs.badgeImageName &&
        lhs.numberOfTabs == rhs.numberOfTabs &&
        lhs.isEnabled == rhs.isEnabled &&
        lhs.shouldDisplayAsHighlighted == rhs.shouldDisplayAsHighlighted &&
        lhs.a11yLabel == rhs.a11yLabel &&
        lhs.a11yHint == rhs.a11yHint &&
        lhs.a11yId == rhs.a11yId
    }
}
